<template>
  <div class="containers">
    <div class="title">请设置密码</div>
    <input :type="eyeType" id="input" ref="input" v-model="password" placeholder="密码">
    <span v-show="eyeType === 'password'" @click="changeType" class="iconfont">&#xe63a;</span>
    <span v-show="eyeType === 'text'" @click="changeType" class="iconfont">&#xe704;</span>
    <div @click="password.length && stepFour()" :class="{disabled: !password.length}" class="next">提交</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'SurePhone',
  data() {
    return {
      password: '',
      /** 来控制input  type类型 */
      eyeType: 'password'
    }
  },
  computed: {
    ...mapState(['phone'])
  },
  mounted() {
    this.$store.dispatch('saveStep', 'stepThree')
  },
  methods: {
     /** 提示 */
    messageTips(type, msg) {
      this.$Message[type]({
        background: true,
        content: msg
      })
    },
    /** 点击眼睛对input类型进行切换 */
    changeType() {
      if (this.eyeType === 'password')
        this.eyeType = 'text'
      else 
        this.eyeType = 'password'
    },
    async stepFour() {
      let result = await this.$api.changePass({phone: this.phone, password: this.password})
      if (result.code === 0) {
        this.$store.dispatch('saveStep', 'stepFour')
        this.$router.push('/findPassword/changeComplete')
      } else 
        this.messageTips('error', '修改密码失败，请稍后重试')
    }
  }
}
</script>

<style lang="scss" scoped>
.containers {
  width: 300px;
  margin: 0 auto;
  position: relative;
  .title {
    font-size: 16px;
    color: #333;
    margin-bottom: 50px;
  }
  input {
    font-size: 16px;
    border: none;
    border-bottom: 1px solid #d8d8d8;
    width: 300px;
    box-sizing: border-box;
    margin-bottom: 30px;
    background-color: #fff !important;
    padding-right: 25px;
  }
  
  .next {
    font-size: 16px;
    background: linear-gradient(135deg,#FFD000 0,#FFBD00 100%);
    border-radius: 8px;
    border: 1px solid #FFD000;
    text-align: center;
    color: #222222;
    height: 36px;
    line-height: 36px;
    cursor: pointer;
    width: 300px;
    display: inline-block;
  }
  .disabled {
    background-image: linear-gradient(135deg,#FFF5CA 0,#FFF2CC 100%);
    color: rgba(34,34,34,.5);
    cursor: not-allowed;
    border: none;
  }
  .iconfont {
    top: 73px;
    position: absolute;
    font-size: 19px;
    right: 2px;
    cursor: pointer;
  }
}
</style>